/**
 * 
 */
package com.gwcloud.leetcode.offers;

import com.gwcloud.leetcode.common.datastructure.ListNode;

/**
 * @ClassName   : Leetcode0220 
 * @author      : ganwei 
 * @date        : 2020年6月2日
 * @Description : Leetcode0220
 */
public class Leetcode0220 {
    public ListNode getKthFromEnd(ListNode head, int k) {
    	ListNode fast = head;
    	ListNode slow = head;
    	while(fast != null && k > 0){
    		fast = fast.next;
    		k--;
    	}
    	if(fast == null && k == 0){
    		return head;
    	}else if(fast == null && k > 0){
    		return null;
    	}
    	while(fast != null){
    		slow = slow.next;
    		fast = fast.next; 
    	}
    	return slow;
    }
    public static void main(String[] args){
    	
    }
}
